{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5573e9fa-cc08-4f86-9bae-d541cd0cdfd5",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/merge-k-sorted-lists\n",
    "\n",
    "\n",
    "Runtime: 189 ms, faster than 25.85% of Python3 online submissions for Merge k Sorted Lists.\n",
    "Memory Usage: 17.8 MB, less than 82.40% of Python3 online submissions for Merge k Sorted Lists.\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def mergeKLists(self, lists: List[Optional[ListNode]]) -> Optional[ListNode]:\n",
    "        #8:56\n",
    "        nodeList = []\n",
    "        \n",
    "        for oneList in lists:\n",
    "            node = oneList\n",
    "            while node:\n",
    "                nodeList.append(node)\n",
    "                node = node.next\n",
    "        \n",
    "        nodeList.sort(key=lambda x: x.val)\n",
    "        \n",
    "        if len(nodeList) == 0: return None\n",
    "        \n",
    "        head = nodeList[0]\n",
    "        lastNode = head\n",
    "        for i, node in enumerate(nodeList[1:]):\n",
    "            lastNode.next = node\n",
    "            lastNode = node\n",
    "        nodeList[-1].next = None\n",
    "        \n",
    "        return head\n",
    "        #8:59\n",
    "        #debug until 9:02\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c47f877f-87cc-4527-9e0d-f0161ad526d0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
